package com.hspedu.homework;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/10
 * @time 18:32
 */
public class Homework03 {
    public static void main(String[] args) {
        Map map = new HashMap();
        Emp jack = new Emp("jack", 650);
        Emp tom = new Emp("tom", 1200);
        Emp smith = new Emp("smith", 2900);
        map.put("jack",650.0);
        map.put("tom",1200.0);
        map.put("smith",2900.0);
        map.put("jack",2600.0);

        System.out.println("工资添加100：");
        Set set1 = map.keySet();
        for (Object key : set1) {
            map.put(key,(Double)map.get(key) + 100);
        }

        System.out.println("遍历员工和工资：");
        Set set = map.entrySet();
        for (Object entry : set) {
            Map.Entry e = (Map.Entry) entry;
            System.out.print(e.getKey()+" "+e.getValue()+"\n");
        }
        System.out.println("遍历工资");
        Iterator iterator = map.values().iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }
    }
}

class Emp{
    private String name;
    private double price;

    @Override
    public String toString() {
        return "Emp{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public Emp(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}
